package com.woparker.kiosk.view;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.woparker.kiosk.R;


/**
 * 气泡
 * Created by zhanghs on 2016/4/14.
 */
public class BubbleView extends LinearLayout {
    Context mContext;
    private TextView titleTextView;

    private TextView messageTextView;

    public BubbleView(Context context) {
        super(context);
        mContext = context;
        initView(context);
    }

    private void initView(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.view_bubble, this, true);
        titleTextView = view.findViewById(R.id.titleTextView);
        messageTextView = view.findViewById(R.id.messageTextView);
    }

    /**
     * 设置气泡中的文字
     * @param title 标题
     * @param message 信息
     */
    public void setBubbleText(String title, String message) {
        titleTextView.setText(title);
        if(TextUtils.isEmpty(message)){
            messageTextView.setVisibility(View.GONE);
        }
        else {
            messageTextView.setVisibility(View.VISIBLE);
            messageTextView.setText(message);
        }
    }

    /**
     * 获取视图宽度
     *
     * @return
     */
    public int getViewWidth() {
        measure(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        return getMeasuredWidth();
    }

    /**
     * 获取视图高度
     *
     * @return
     */
    public int getViewHeight() {
        measure(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        return getMeasuredHeight();
    }

}
